package com.ms.es.sql;

import java.io.Serializable;

import com.ms.common.utils.StringUtils;
import com.ms.es.common.EsOperateConstant;
import com.ms.es.enums.CommandType;
import com.ms.es.enums.EsActionEnum;

import lombok.Data;

@Data
public class SqlDesc implements Serializable {

    private static final long serialVersionUID = 1L;

    private String index;

    private EsActionEnum actionEnum;

    private String urlParam;

    private Object id;

    private String key;

    private String dsl;

    private CommandType commandType;

    private Class<?> resultType;

    private Class<?> returnType;

    private boolean returnsMany;

    private boolean returnsVoid;

    public String getRequestPath() {
        StringBuilder path = new StringBuilder();
        if (StringUtils.isNotEmpty(index)) {
            path.append("/");
            path.append(index);
        }

        if (actionEnum != null) {
            path.append("/");
            path.append(actionEnum.getValue());
        }
        if (StringUtils.isNotEmpty(urlParam)) {
            path.append("?");
            path.append(urlParam);
        }
        return path.toString();
    }

    public String getRestFulPath() {
        StringBuilder path = new StringBuilder();
        if (StringUtils.isNotEmpty(index)) {
            path.append("/");
            path.append(index);
        }
        if (actionEnum != null) {
            path.append("/");
            path.append(actionEnum.getValue());
        }
        if (id != null) {
            path.append("/");
            path.append(id);
        }
        return path.toString();
    }

    public String getRestSqlPath() {
        StringBuilder path = new StringBuilder();
        if (actionEnum != null) {
            path.append("/");
            path.append(actionEnum.getValue());
        }
        path.append("?").append(EsOperateConstant.SQL_FORMAT);
        return path.toString();
    }

}
